package com.app.controller;

import com.app.model.UserModel;
import com.app.service.SubsidyApplicationService;
import com.app.service.UserService;
import com.app.util.Result;
import com.app.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/subsidyApplication")
public class SubsidyApplicationController {


    @Autowired
    private SubsidyApplicationService subsidyApplicationService;

    @Autowired
    private UserService userService;
    /**
     * 小程序————高校补贴申领状态列表查询
     */
    @GetMapping("/subsidyApplicationList")
    public Result subsidyApplicationList(@RequestParam(required = false,defaultValue = "1") Integer page ,@RequestParam(required = false,defaultValue = "10") Integer limit, HttpServletRequest request) {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        return subsidyApplicationService.subsidyApplicationList(page,limit,user);
    }





}
